package com.childenglish.validation;

import com.childenglish.utils.ValidationPatterns;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 可选邮箱验证器
 */
public class OptionalEmailValidator implements ConstraintValidator<OptionalEmail, String> {
    
    @Override
    public void initialize(OptionalEmail constraintAnnotation) {
        // 初始化方法
    }
    
    @Override
    public boolean isValid(String email, ConstraintValidatorContext context) {
        // 如果值为空或null，则跳过验证
        if (email == null || email.trim().isEmpty()) {
            return true;
        }
        return ValidationPatterns.EMAIL_PATTERN.matcher(email).matches();
    }
}

